Page({
  data: {
    items1: [{
        name: 'serverkind1',
        value: '口述史',
        checked: 'true'
      },
      {
        name: 'serverkind2',
        value: '个人志',
      },
      {
        name: 'serverkind3',
        value: '纪录片'
      },
    ],
    items2: [{
        name: 'resultkind1',
        value: '电子文本',
        checked: 'true'
      },
      {
        name: 'resultkind2',
        value: '纸质文本',
        checked: 'true'
      }
    ],
    formData: {

    },
    rules: [{
      name: 'textLength',
      rules: [{
        required: true,
        message: 'textLength必填'
      }, {
        min: 0,
        message: '文本数目最小为0'
      }],
    }, {
      name: 'time',
      rules: {
        range: [0, 24],
        message: '时间在0到24个月之间'
      },
    }, {
      name: "textWordsNum",
      rules: {
        min: 0,
        message: '文本字数至少为0'
      }
    }]

  },
  checkboxChange: function (e) {
    console.log('checkbox发生change事件，携带value值为：', e.detail.value)
  },
  formInputChange(e) {
    const {
      field
    } = e.currentTarget.dataset
    this.setData({
      [`formData.${field}`]: e.detail.value
    })
    console.log(this.data.formData)
  },
  submitForm: function (e) {
    console.log("submitform中的e:")
    console.log(e)
    this.selectComponent('#form').validate((valid, errors) => {
      console.log('valid', valid, errors)
      if (!valid) {
        const firstError = Object.keys(errors)
        if (firstError.length) {
          this.setData({
            error: errors[firstError[0]].message
          })
        }
      } else {
        wx.showToast({
          title: '校验通过'
        })
      }
    })
  }
})